package com.nbsaas.boot.scm.data.entity;

import com.nbsaas.boot.code.annotation.*;
import com.nbsaas.boot.jpa.data.entity.AbstractEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import lombok.Data;
import org.hibernate.annotations.Comment;

import java.math.BigDecimal;
import java.util.Date;

@CreateByUser
@ComposeView
@Data
@FormAnnotation(title = "采购订单", model = "采购订单")
@Entity
@Table(name = "bs_purchase_order")
@Comment("采购订单表")
public class PurchaseOrder extends AbstractEntity {

    @Comment("采购订单编号")
    @SearchItem(name = "orderNo", key = "orderNo", label = "采购订单编号")
    @FormField(title = "采购订单编号", sortNum = "1", grid = true, required = true)
    @Column(length = 50, nullable = false, unique = true)
    private String orderNo;

    @Comment("采购订单标题")
    @SearchItem(name = "title", key = "title", label = "采购订单标题")
    @FormField(title = "采购订单标题", sortNum = "2", grid = true, required = true)
    @Column(length = 200, nullable = false)
    private String title;

    @Comment("供应商ID")
    @FormField(title = "供应商", sortNum = "3", grid = true, type = InputType.select, required = true)
    private Long supplierId;

    @Comment("供应商编码")
    @FormField(title = "供应商编码", sortNum = "4", grid = true)
    @Column(length = 50)
    private String supplierCode;

    @Comment("供应商名称")
    @FormField(title = "供应商名称", sortNum = "5", grid = true)
    @Column(length = 200)
    private String supplierName;

    @Comment("采购类型")
    @FormField(title = "采购类型", sortNum = "6", grid = true, type = InputType.select)
    @Column(length = 50)
    private String purchaseType; // DIRECT-直接采购, TENDER-招标采购, NEGOTIATION-谈判采购

    @Comment("采购方式")
    @FormField(title = "采购方式", sortNum = "7", grid = true, type = InputType.select)
    @Column(length = 50)
    private String purchaseMethod; // CASH-现金采购, CREDIT-信用采购, ADVANCE-预付款采购

    @Comment("订单状态")
    @FormField(title = "订单状态", sortNum = "8", grid = true, type = InputType.select)
    @Column(length = 20)
    private String orderStatus; // DRAFT-草稿, SUBMITTED-已提交, APPROVED-已审批, CONFIRMED-已确认, IN_PROCESS-采购中, PARTIAL_RECEIVED-部分收货, COMPLETED-已完成, CANCELLED-已取消

    @Comment("审批状态")
    @FormField(title = "审批状态", sortNum = "9", grid = true, type = InputType.select)
    @Column(length = 20)
    private String approvalStatus; // PENDING-待审批, APPROVED-已审批, REJECTED-已拒绝

    @Comment("采购员ID")
    @FormField(title = "采购员", sortNum = "10", grid = true, type = InputType.select)
    private Long purchaserId;

    @Comment("采购员姓名")
    @FormField(title = "采购员姓名", sortNum = "11", grid = true)
    @Column(length = 100)
    private String purchaserName;

    @Comment("部门ID")
    @FormField(title = "部门", sortNum = "12", grid = true, type = InputType.select)
    private Long departmentId;

    @Comment("部门名称")
    @FormField(title = "部门名称", sortNum = "13", grid = true)
    @Column(length = 100)
    private String departmentName;

    @Comment("预计交货日期")
    @FormField(title = "预计交货日期", sortNum = "14", type = InputType.date, grid = true)
    private Date expectedDeliveryDate;

    @Comment("实际交货日期")
    @FormField(title = "实际交货日期", sortNum = "15", type = InputType.date, grid = true)
    private Date actualDeliveryDate;

    @Comment("订单总金额")
    @FormField(title = "订单总金额", sortNum = "16", grid = true, type = InputType.el_input_number, sort = true)
    @Column(precision = 15, scale = 2)
    private BigDecimal totalAmount;

    @Comment("已付金额")
    @FormField(title = "已付金额", sortNum = "17", grid = true, type = InputType.el_input_number)
    @Column(precision = 15, scale = 2)
    private BigDecimal paidAmount;

    @Comment("未付金额")
    @FormField(title = "未付金额", sortNum = "18", grid = true, type = InputType.el_input_number)
    @Column(precision = 15, scale = 2)
    private BigDecimal unpaidAmount;

    @Comment("税率")
    @FormField(title = "税率", sortNum = "19", grid = true, type = InputType.el_input_number)
    @Column(precision = 5, scale = 2)
    private BigDecimal taxRate;

    @Comment("税额")
    @FormField(title = "税额", sortNum = "20", grid = true, type = InputType.el_input_number)
    @Column(precision = 15, scale = 2)
    private BigDecimal taxAmount;

    @Comment("折扣率")
    @FormField(title = "折扣率", sortNum = "21", grid = true, type = InputType.el_input_number)
    @Column(precision = 5, scale = 2)
    private BigDecimal discountRate;

    @Comment("折扣金额")
    @FormField(title = "折扣金额", sortNum = "22", grid = true, type = InputType.el_input_number)
    @Column(precision = 15, scale = 2)
    private BigDecimal discountAmount;

    @Comment("运费")
    @FormField(title = "运费", sortNum = "23", grid = true, type = InputType.el_input_number)
    @Column(precision = 15, scale = 2)
    private BigDecimal freightAmount;

    @Comment("其他费用")
    @FormField(title = "其他费用", sortNum = "24", grid = true, type = InputType.el_input_number)
    @Column(precision = 15, scale = 2)
    private BigDecimal otherAmount;

    @Comment("付款条件")
    @FormField(title = "付款条件", sortNum = "25", grid = true)
    @Column(length = 200)
    private String paymentTerms;

    @Comment("交货地址")
    @FormField(title = "交货地址", sortNum = "26", grid = true)
    @Column(length = 500)
    private String deliveryAddress;

    @Comment("联系人")
    @FormField(title = "联系人", sortNum = "27", grid = true)
    @Column(length = 100)
    private String contactPerson;

    @Comment("联系电话")
    @FormField(title = "联系电话", sortNum = "28", grid = true)
    @Column(length = 20)
    private String contactPhone;

    @Comment("备注")
    @FormField(title = "备注", sortNum = "29", type = InputType.textarea)
    @Column(columnDefinition = "text")
    private String remark;

    @Comment("审批意见")
    @FormField(title = "审批意见", sortNum = "30", type = InputType.textarea)
    @Column(columnDefinition = "text")
    private String approvalComment;

    @Comment("审批人ID")
    @FormField(title = "审批人", sortNum = "31", grid = true, type = InputType.select)
    private Long approverId;

    @Comment("审批人姓名")
    @FormField(title = "审批人姓名", sortNum = "32", grid = true)
    @Column(length = 100)
    private String approverName;

    @Comment("审批时间")
    @FormField(title = "审批时间", sortNum = "33", type = InputType.date, grid = true)
    private Date approvalTime;
} 